package com.es.hr.areartm;

import java.util.ArrayList;
import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;

import com.es.util.page.PageBean;
import com.es.util.page.PageNavigator;
import com.opensymphony.webwork.interceptor.ServletRequestAware;
import com.opensymphony.xwork.ActionSupport;

public class AreaRTMSearchInitAction  extends ActionSupport implements ServletRequestAware{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	HttpServletRequest request;
	 
	   public String execute()throws Exception
	   {
		   String queryName = request.getParameter("queryName")==null?"":request.getParameter("queryName");
		   String curpage = request.getParameter("curpage")==null?"1":request.getParameter("curpage");
		   String queryLogin = request.getParameter("queryLogin")==null?"":request.getParameter("queryLogin");
		   String emp_role = "RTM";
		   String emp_city_code = request.getParameter("emp_city_code")==null?"":request.getParameter("emp_city_code");
		   String emp_province_code = request.getParameter("emp_province_code")==null?"":request.getParameter("emp_province_code");
		   String emp_area_code = request.getParameter("emp_area_code")==null?"":request.getParameter("emp_area_code");
		   String queryEmpCode = request.getParameter("queryEmpCode")==null?"":request.getParameter("queryEmpCode");
		   String queryEmpJob = request.getParameter("queryEmpJob")==null?"":request.getParameter("queryEmpJob");
		   
		   String message = (String)request.getAttribute("message");
		   

		   AreaRTMBiz manegeBiz = new AreaRTMBiz();
		 		   
		   PageNavigator pageNav = new PageNavigator();
		   if(!curpage.equals(""))
			   pageNav.setCurpage(Integer.parseInt(curpage));
		   ArrayList<String> param = new ArrayList<String>();
		   param.add("");
		   param.add("");
		   param.add("");
		   param.add("");
		   param.add(emp_role);
		   param.add("");	
		   param.add("");
		   param.add("");
		   PageBean pageBean  = manegeBiz.queryEmpList(pageNav, param);
		   request.setAttribute("pageBean", pageBean);
		   request.setAttribute("queryName", "");
		   request.setAttribute("queryLogin", "");
		   request.setAttribute("emp_role", emp_role);
		   request.setAttribute("emp_city_code", "");
		   request.setAttribute("emp_province_code", "");
		   request.setAttribute("emp_area_code", "");
		   request.setAttribute("queryEmpCode", "");
		   request.setAttribute("queryEmpJob", "");
		   
		   for(int i = 0; i < pageBean.getMap().size(); ++i){
			   HashMap<String, Object> map = pageBean.getMap().get(i);
			   String empId = map.get("emp_id").toString();
			   String count = manegeBiz.computeCountByEmpId(empId);
			   map.put("emp_area_count", count);
		   }
		   if(message!=null)
			   request.setAttribute("message", message);
		   return "success";
	   }
	
	   public void setServletRequest(HttpServletRequest request) {
		     this.request = request;
		   }
}
